package com.pulook.daikuan.dao;

import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class SessionUtil {
	/**
	 * 这个session是根据上下文取出的
	 * 
	 * @return
	 */
	public static HttpSession getSession() {
		HttpSession session = ((ServletRequestAttributes) RequestContextHolder
				.getRequestAttributes()).getRequest().getSession();
		return session;
	}

	public static void setAttributeForSession(String key, Object object) {
		getSession().setAttribute(key, object);
	}

	public static Object getAttributeFromSessionByKey(String key) {
		Object object = getSession().getAttribute(key);
		return object;
	}

	public static void deleteAttributeFromSessionByKey(String key) {
		getSession().removeAttribute(key);
	}
	
	public static void delSession(){
		getSession().invalidate();
	}
}
